/**
 * @file imgviewer.h
 *
 */
#ifndef IMGVIEWER_H
#define IMGVIEWER_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif

#if USE_LV_WATCH_IMGVIEWER != 0

/*********************
 *      DEFINES
 *********************/
#define IMGVIEWER_MAX_COUNT 1000
#define IMGVIEWER_IMG_COUNT_PER_PAGE 9
#define IMGVIEWER_TAB_COUNT 3
#define IMGVIEWER_PATH_MAX  260
#define IMGVIEWER_PATH_LEN (260*2)
#define IMGVIEWER_SHARE_TMEP_PATH  "C:/imgviewer_share_temp"

/* File attribute bits for directory entry (for ui used)*/
#define IMGVIEWER_FILE_DIR    0x10    /* Directory */
#define IMGVIEWER_FILE_ARC    0x20    /* Archive, normal file */
#define IMGVIEWER_FILE_HID    0x40    /* Hidden, hide(or system) dir(or file) */
#define IMGVIEWER_EXT_NAME    "jpg"
#define IMGVIEWER_EXT_NAME_SUB    "png"

#ifndef BUILD_IN_PC_SIMULATOR
#define IMGVIEWER_ROOT_PATH   "D:\\*"
#define IMGVIEWER_PATH_FILE   "D:\\img_list.nv"
#define IMGVIEWER_WRITE_PATH_FILE 0
#else
#define IMGVIEWER_ROOT_PATH   "C:/*"
#define IMGVIEWER_PATH_FILE   "C:/img_list.nv"
#define IMGVIEWER_WRITE_PATH_FILE 1
#endif

#define IMGVIEWER_THUMBNAIL_W 72
#define IMGVIEWER_THUMBNAIL_H 64
#define IMGVIEWER_DEL_PREVIEW_W 100
#define IMGVIEWER_DEL_PREVIEW_H 100
#define IMGVIEWER_MAX_W 320
#define IMGVIEWER_MAX_H 320
#define IMGVIEWER_MAX_FILE_SIZE (1024 * 100) //100KB

#define IMGVIEWER_SD_MOUNTED_AS_U_STORAGE -1

/**********************
 *      TYPEDEFS
 **********************/
typedef struct {
    char path[IMGVIEWER_PATH_MAX];
    char filename[IMGVIEWER_PATH_MAX];
} img_info_t;

typedef struct {
    lv_img_dsc_t *preview_src;
    uint32_t index;
    uint32_t img_w;
    uint32_t img_h;
    uint8_t selected;
} imgviewer_photo_info_t;

typedef struct {
    lv_watch_obj_ext_t lv_watch_obj;
    /*New data for this type */
    lv_obj_t * orderopt_label;
    lv_obj_t * img_page;
    lv_obj_t * obj_par;
    lv_obj_t * tabview;
    lv_obj_t * del_bg;
    lv_obj_t * share_bg;
    uint32_t photo_cnt;
    uint32_t photo_curr_page_start_index;
    uint32_t photo_tabview_start_index;
    uint32_t photo_tabview_curr_index;
    uint8_t time_order;          /*1--time order, 0--time reverse order*/
    uint8_t preview_mode;        /*1--select mode, 0--view mode*/
    uint8_t from_camera;
    uint8_t selected_cnt;
    bool pressing;
    TIMER_ID timer;
    bool ext_create;
} lv_imgviewer_obj_ext_t;

enum {
    IMGVIEWER_BACK_ORDER_SET = 1,
    IMGVIEWER_BACK_QUIT,
    IMGVIEWER_BACK_SETTING,
    IMGVIEWER_BACK_VIEW_PHOTO,
    IMGVIEWER_BACK_SEL_SHARE,
    IMGVIEWER_BACK_SEL_DEV,
};
typedef uint8_t imgviewer_back_free_num;

/**********************
 * GLOBAL PROTOTYPES
 **********************/
void imgviewer_create_event_cb(lv_obj_t * btn, lv_event_t e);
lv_res_t imgviewer_create_from_camera(void);
lv_obj_t * imgviewer_create(lv_obj_t * activity_obj);
lv_imgviewer_obj_ext_t * imgviewer_get_ext(void);
void imgviewer_photo_ll_init(void);
void imgviewer_photo_ll_destroy(void);
const lv_ll_t * imgviewer_get_photo_ll(void);
void imgviewer_photo_share_event_cb(lv_obj_t * img, lv_event_t e);
void imgviewer_photo_share_flag_reset(void);
lv_fs_res_t imgviewer_photo_path_write(char * str);
uint32_t imgviewer_photo_ll_get_nodecnt(void);
void imgviewer_photo_path_init(void);
void imgviewer_load_one_photo_path(char *path, char *filename, uint32_t img_w, uint32_t img_h);
void imgviewer_load_all_photo_path(void);
void imgviewer_destory(bool start_cam);
#if USE_LV_BLUETOOTH != 0
void imgviewer_select_share_way(lv_obj_t * par);
void imgviewer_send_file_finish_action(void);
#endif
#if USE_LV_WATCH_SD_AUTO_MOUNT != 0
extern void imgviewer_for_mount_destory(void);
#endif

/**********************
 *      MACROS
 **********************/



#endif /*USE_LV_WATCH_IMGVIEWER*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*IMGVIEWER_H*/
